//
//  MovieDetailView.m
//  DaHaiDouBan
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 Wang Dahai. All rights reserved.
//

#import "MovieDetailView.h"
#import "UIImageView+WebCache.h"
@implementation MovieDetailView
- (void)dealloc
{
    [_detailImageView release];
    [_rating_AND_rating_count_Label release];
    [_release_date_Label release];
    [_runtimeLabel release];
    [_genresLabel release];
    [_film_locations_Label release];
    [_actorsLabel release];
    [_plot_simple_Label release];
    [_plot_simple_Head_Label release];
    [_collectButtonn release];
    [super dealloc];
}
-(instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
        
    }
    
    return self;
    
}
-(void)createSubviews
{

    self.detailImageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 60, 110, 150)];
    [self addSubview:self.detailImageView];
    [self.detailImageView release];
    //评分+评论
    self.rating_AND_rating_count_Label = [[UILabel alloc] initWithFrame:CGRectMake(140, 60, 200, 28)];
    [self addSubview:self.rating_AND_rating_count_Label];
    [self.rating_AND_rating_count_Label release];
    //时间
    self.release_date_Label = [[UILabel alloc] initWithFrame:CGRectMake(140, 90, 90, 28)];
    [self addSubview:self.release_date_Label];
    [self.release_date_Label release];
    //电影时长
    self.runtimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 120, 200, 28)];
    [self addSubview:self.runtimeLabel];
    [self.runtimeLabel release];
    //类型
    self.genresLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 150, 200, 28)];
    [self addSubview:self.genresLabel];
    [self.genresLabel release];
    //语言
    self.film_locations_Label = [[UILabel alloc] initWithFrame:CGRectMake(140, 180, 200, 28)];
    [self addSubview:self.film_locations_Label];
    [self.film_locations_Label release];
    //收藏按钮
    self.collectButtonn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.collectButtonn.frame = CGRectMake(125,233 , 26, 24);
    [self.collectButtonn setBackgroundImage:[UIImage imageNamed:@"ic_star_half@2x"] forState:UIControlStateNormal];
    [self.collectButtonn setBackgroundImage:[UIImage imageNamed:@"ic_star_red@2x"] forState:UIControlStateSelected];
    [self addSubview:self.collectButtonn];
    [self.collectButtonn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UILabel *actors_Head_Label = [[UILabel alloc] initWithFrame:CGRectMake(25, 230, 100, 50)];
    actors_Head_Label.text = @"制作人";
    actors_Head_Label.font = [UIFont systemFontOfSize:20];
    [self addSubview:actors_Head_Label];
    [actors_Head_Label release];
    //制片人
    self.actorsLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 270, 325, 40)];
    self.actorsLabel.font = [UIFont systemFontOfSize:15];
    self.actorsLabel.numberOfLines = 0;
    [self addSubview:self.actorsLabel];
    [self.actorsLabel release];
    
    self.plot_simple_Head_Label = [[UILabel alloc] initWithFrame:CGRectMake(25, 320, 325, 50)];
    self.plot_simple_Head_Label.text = @"电影情节";
    self.plot_simple_Head_Label.font = [UIFont systemFontOfSize:20];
    [self addSubview:self.plot_simple_Head_Label];
    [self.plot_simple_Head_Label release];
    //电影情节介绍
    self.plot_simple_Label = [[UILabel alloc] initWithFrame:CGRectMake(25, 360, 325, 400)];
    self.plot_simple_Label.numberOfLines = 0;
    self.plot_simple_Label.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.plot_simple_Label];
    [self.plot_simple_Label release];
    
}

-(void)setMovieDetai:(MovieDetail *)movieDetai
{
    
    if (_movieDetai != movieDetai) {
        
        [_movieDetai release];
        
        _movieDetai = [movieDetai retain];
        
        
    }
    
    [self.detailImageView sd_setImageWithURL:[NSURL URLWithString:_movieDetai.poster] placeholderImage:[UIImage imageNamed:@"picholder@2x"]];

    self.release_date_Label.text = _movieDetai.release_date;
    self.actorsLabel.text = _movieDetai.actors;
    self.runtimeLabel.text = _movieDetai.runtime;
    self.plot_simple_Label.text = _movieDetai.plot_simple;
    self.genresLabel.text = _movieDetai.genres;
    NSString *rating1 = _movieDetai.rating;
    NSString *ratingCount = _movieDetai.rating_count;
    self.rating_AND_rating_count_Label.text = [NSString stringWithFormat:@"评分: %@   (%@评论)",rating1,ratingCount];
    self.film_locations_Label.text = _movieDetai.language;
}
-(void)buttonAction:(UIButton *)btn
{
    

    if (self.collectButtonn.selected == NO) {
        NSLog(@"收藏");
        
    }else
    {
        NSLog(@"未收藏");
        
    }
    
    self.collectButtonn.selected = ! self.collectButtonn.selected;
    
    
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
